export class cssAnalyser {
  key: string = "";
  val: string = "";
  comment: string = "";
  constructor(line: string) {
    let x = [],
      i = 0;

    const removeComment = this.removeCSSComments(line);
    this.comment = removeComment.removedComments[0];
    line = removeComment.cssString.trim();

    for (; i < line.length; i++) {
      if (/[a-zA-Z\-]/.test(line[i])) x.push(line[i]);
      else if (line[i] === ":") break;
    }
    this.key = x.join("").trim();

    this.val = line.substring(i + 1, line.length - 1).trim();
  }
  private removeCSSComments(cssString: string) {
    const commentRegex = /(\/\*[\s\S]*?\*\/)/g;
    const matches = cssString.match(commentRegex);
    if (matches) {
      let removedComments = matches.map((comment: string) => {
        cssString = cssString.replace(comment, "");
        return comment;
      });
      return {
        cssString,
        removedComments,
      };
    } else {
      return {
        cssString,
        removedComments: [""],
      };
    }
  }
  public getKey(): string {
    return this.key;
  }
  public getVal(): string {
    return this.val;
  }
  public getComment() {
    return this.comment;
  }
}
